/*
 ** uri {String 接口}
 ** formData {Object 需要传入的参数}
 ** yeming 2019/3/8
 */

import COOKIE from "@/common/scripts/cookie";
import O from "@/common/scripts";
import $md5 from 'js-md5';

const NEWSALT_LIVE = "BkR/+ZEzGHwPQ"; // 直播项目固定盐
const NEWSALT_GCS = "Gcdct/wCqSxd"; // 地面站项目固定盐
const ORIGINDATA = {
  token: 'ab527m34e8omaeb6vh29voe5p6',
  v: '4-1-2.0.0-2-0', // 第四位数值 1 正式 2 预发布
  t: '',
  qzid: "2" // 1 正式 2 预发布
};

export function handleDataAndSign (api, uri, data) {
  let paramsStr = "";
  let handleData = {};
  let originData = O.shallowClone(ORIGINDATA);
  originData.t = new Date().getTime();
  handleData = Object.assign(originData, data);
  if (COOKIE.get("yxla_token")) {
    handleData.token = COOKIE.get("yxla_token");
  }
  paramsStr = O.getObjStr(handleData);
  if (api === '/liveapi') {
    handleData.s = $md5(uri + paramsStr + NEWSALT_LIVE);
  }
  if (api === '/gcsapi') {
    handleData.s = $md5(uri + paramsStr + NEWSALT_GCS);
  }
  return handleData;
}
